<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage PluginsFunction
 */

/**
 * Smarty {format_description} function plugin
 *
 * Type:     function<br>
 * Name:     format_description<br>
 * Purpose:  print out a counter value
 * @author Monte Ohrt <monte at ohrt dot com>
 * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
 *       (Smarty online manual)
 * @param array parameters
 * @param Smarty
 * @param object $template template object
 * @return string|null
 */
function smarty_function_format_description($params, $template)
{
	// correct pattern to add here
   	$pattern = '@(?<![.*">])\b(?:(?:https?|ftp|file)://|[a-z]\.)[-A-Z0-9+&#/%=~_|$?!:,.]*[A-Z0-9+&#/%=~_|$\/]@i';   	
	$replacement = '<a href="\0" target="_blank">\0</a>';	
	$text = preg_replace($pattern, $replacement, $params['text']);
	$text = nl2br($text);
	return $text;    
}